<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //rest:剩下的
      function add(m, ...aaa) {
        //m=100，aaa是个数组，包含四个实际参数，除了100,
        let result = m
        for (let item of aaa) {
          result += item
        }
        return result
      }
      console.log(add(100, 200, 300, 400))

      //2、表明函数中可以有剩余参数
      function add2(...aaa) {
        let result = 0
        for (let item of aaa) {
          result += item
        }
        return result
      }

      console.log(add2(100, 200, 300, 400))

      //3、剩余参数解构运算
      function add3(...[a, b, c, d]) {
        return a + b + c + d
      }

      console.log(add3(100, 200, 300, 400))

      //500是没有使用的，等价于let[a,b,c,d]=[100,200,300,400,500]
      console.log(add3(100, 200, 300, 400, 500))
    </script>
  </body>
</html>
